//
//  AuthenCompanyMarketMsgVM.swift
//  kxf
//
//  Created by Mac on 2024/3/8.
//

import Foundation
import UIKit
import SwiftUI

class AuthenCompanyMarketMsgVM: UIView {
    
    var selfHeight = RegisterViewHeadTitleVM().selfHeight+RegisterInputVM().selfHeight*5
    
    var controller = WHBaseViewVC()
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var titleVm : RegisterViewHeadTitleVM = {
        let vm = RegisterViewHeadTitleVM.init(frame: CGRect.init(x: 0, y: 0, width: 0, height: 0))
        vm.titleLabel.text = "门店信息"
        return vm
    }()
    lazy var marketNameVm : RegisterInputVM = {
        let vm = RegisterInputVM.init(frame: CGRect.init(x: 0, y: self.titleVm.frame.maxY, width: 0, height: 0))
        vm.leftLabel.text = "门店名称"
        vm.textField.placeholder = "请输入门店全称"
        vm.textField.keyboardType = .default
        vm.maxLength = 40
        return vm
    }()
    lazy var marketContactVm : RegisterInputVM = {
        let vm = RegisterInputVM.init(frame: CGRect.init(x: 0, y: self.marketNameVm.frame.maxY, width: 0, height: 0))
        vm.leftLabel.text = "门店联系人"
        vm.textField.placeholder = "请输入门店联系人"
        vm.textField.keyboardType = .default
//        vm.maxLength = 30
        return vm
    }()
    lazy var marketPhoneVm : RegisterInputVM = {
        let vm = RegisterInputVM.init(frame: CGRect.init(x: 0, y: self.marketContactVm.frame.maxY, width: 0, height: 0))
        vm.leftLabel.text = "联系人手机号"
        vm.textField.placeholder = "请填写联系人手机号"
        vm.textField.keyboardType = .numberPad
        vm.maxLength = 11
        return vm
    }()
    lazy var marketProvinceVm : RegisterInputVM = {
        let vm = RegisterInputVM.init(frame: CGRect.init(x: 0, y: self.marketPhoneVm.frame.maxY, width: 0, height: 0))
        vm.leftLabel.text = "门店所在地区"
        vm.textField.placeholder = "请选择门店所在省市区"
        vm.showArrowImg()
        vm.tapBlock = {()in
//            self.choiceTimeEndAction()
        }
        return vm
    }()
    lazy var marketAddressVm : RegisterInputVM = {
        let vm = RegisterInputVM.init(frame: CGRect.init(x: 0, y: self.marketProvinceVm.frame.maxY, width: 0, height: 0))
        vm.leftLabel.text = "店铺详细地址"
        vm.textField.placeholder = "请输入门店详细地址"
        vm.textField.keyboardType = .default
        vm.maxLength = 60
//        vm.showArrowImg()
        return vm
    }()
}

extension AuthenCompanyMarketMsgVM{
    func initUI() {
        addSubview(titleVm)
        addSubview(marketNameVm)
        addSubview(marketContactVm)
        addSubview(marketPhoneVm)
        addSubview(marketProvinceVm)
        addSubview(marketAddressVm)
    }
    func updateUIForRefuse() {
        marketNameVm.textField.text = AuthenCompanyMsgModel.shareInstance.mercName
        marketContactVm.textField.text = AuthenCompanyMsgModel.shareInstance.mercContactName
        marketPhoneVm.textField.text = AuthenCompanyMsgModel.shareInstance.mercContactPhone
        marketProvinceVm.setLabelContent(content: "\(AuthenCompanyMsgModel.shareInstance.mercAddressProvinceName)\(AuthenCompanyMsgModel.shareInstance.mercAddressCityName)\(AuthenCompanyMsgModel.shareInstance.mercAddressAreaName)")
        marketAddressVm.textField.text = AuthenCompanyMsgModel.shareInstance.mercAddress
    }
}

extension AuthenCompanyMarketMsgVM{
    func getValue() {
        AuthenCompanyMsgModel.shareInstance.mercName = marketNameVm.textField.text ?? ""
        AuthenCompanyMsgModel.shareInstance.mercContactName = marketContactVm.textField.text ?? ""
        AuthenCompanyMsgModel.shareInstance.mercContactPhone = marketPhoneVm.textField.text ?? ""
//        AuthenCompanyMsgModel.shareInstance
        AuthenCompanyMsgModel.shareInstance.mercAddress = marketAddressVm.textField.text ?? ""
    }
}
